package com.sise.thread;

import java.util.Random;

/**
 * 作者：idea
 * 日期：2018/6/28
 * 描述：
 */
public class ThreadLocals {
    public static class myRunnable implements Runnable{

        private ThreadLocal<Integer> threadLocal=new ThreadLocal();

        @Override
        public void run() {
            threadLocal.set(new Random().nextInt(10));
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread()+":"+threadLocal.get());
        }

    }

    public static void main(String[] args) {
        myRunnable t=new myRunnable();
        System.out.println("this is start");
        Thread t1=new Thread(t);
        Thread t2=new Thread(t);
        t1.start();
        t2.start();
    }
}

